/*
 * PlacePanelSmall.java
 * 
 * Created on 08-sep-2007, 13:46:43
 */

package swagenda.ui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;

import swagenda.data.Service;
import swagenda.utils.Utils;

/**
 *
 * @author jorge
 */
@SuppressWarnings("serial")
public class PlacePanelSmall extends JPanel
{
    public Service place;
    public JLabel nameLabel;
    public JLabel phoneLabel;

    JPanel icon = new JPanel();
    JPanel text = new JPanel();

    public static final int X_SIZE = 210;
    public static final int Y_SIZE = 42;

    public PlacePanelSmall(Service place)
    {
        this.place = place;
        initPanel();
    }
    
    public PlacePanelSmall()
    {
        initPanel();
    }
    
    public void initPanel()
    {
        setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));
        
        text.setLayout(new BoxLayout(text, BoxLayout.Y_AXIS));
        text.setPreferredSize(new Dimension(190, 50));
        text.setBorder(BorderFactory.createEmptyBorder(0,10,0,0));
        
        setBackground(Color.lightGray);
        
        icon.setBackground(place.privacy.color);
        icon.setToolTipText(place.privacy.key);
        text.setBackground(new Color(255,255,102,200));
        text.setToolTipText(place.name);
        icon.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent evt) {
                smallPlaceIconClicked(evt);
            }
        });
        
        setOpaque(true);
        setPreferredSize(new Dimension(X_SIZE,Y_SIZE));
        nameLabel = new JLabel(place.name);
        nameLabel.setFont(new Font("Dialog", 0, 16));
        phoneLabel = new JLabel(place.phone);
        phoneLabel.setFont(new Font("Dialog", 0, 16));
        setBorder(BorderFactory.createLineBorder(Color.lightGray));
        text.add(nameLabel);
        text.add(phoneLabel);

        add(icon);
        add(text);
    }

    public void smallPlaceIconClicked(MouseEvent evt)
    {
    	MainFrame mainFrame = (MainFrame) Utils.getParentFrame(this);
        PlaceWindowLarge big = new PlaceWindowLarge(mainFrame, place);
        big.setLocationRelativeTo(mainFrame);
        big.setVisible(true);
    }
}
